//
//  SXTTabBarViewController.m
//  
//
//  Created by ma c on 16/8/18.
//
//


#import "SXTTabBarViewController.h"
#import "SXTNavgationController.h"

@interface SXTTabBarViewController ()

@property (nonatomic,strong) NSArray * tabBarMessageArray;

@end

@implementation SXTTabBarViewController

-(NSArray *)tabBarMessageArray {

    if (!_tabBarMessageArray) {
        _tabBarMessageArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"SXTTabBarViewController" ofType:@"plist"]];
    }
    return _tabBarMessageArray;
}

-(void)viewDidLoad {
    
    [super viewDidLoad];
    //通过appearance统一设置所有的UITabBarItem文字属性
    
    UITabBarItem * item = [UITabBarItem appearance];
    [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10.0f],NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
    
    [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10.0f],NSForegroundColorAttributeName:[UIColor colorWithRed:57.0/255.0 green:167/255.0 blue:241/255.0 alpha:1]} forState:UIControlStateSelected];
    
    //添加子控制器
    for (NSDictionary * dic in self.tabBarMessageArray) {
        Class viewControllerClass = NSClassFromString(dic[@"tabbarController"]);
        UIViewController * viewController = [[viewControllerClass alloc]init];
        viewController.tabBarItem.image = [UIImage imageNamed:dic[@"tabbarImage"]];
        viewController.tabBarItem.selectedImage = [UIImage imageNamed:dic[@"tabbarSelectImage"]];
        viewController.title = dic[@"tabbarTitle"];
        
        SXTNavgationController * navigation = [[SXTNavgationController alloc]initWithRootViewController:viewController];
        

        [self addChildViewController:navigation];
    }
    

}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
